package de.bomberman.appstate;

import com.jme3.app.Application;
import com.jme3.app.state.AbstractAppState;
import com.jme3.app.state.AppStateManager;
import com.jme3.niftygui.NiftyJmeDisplay;
import de.lessvoid.nifty.Nifty;
import de.lessvoid.nifty.screen.Screen;
import de.lessvoid.nifty.screen.ScreenController;
import java.util.logging.Logger;

/**
 *
 * @author Mats
 */
public class MenuState extends AbstractAppState implements ScreenController {

    private MainApp app;
    // nifty
    private Nifty nifty;
    private NiftyJmeDisplay niftyDisplay;
    
    // Logger
    private static final Logger logger = Logger.getLogger(MenuState.class.getName());

 
    @Override
    public void initialize(AppStateManager stateManager, Application app) {
        super.initialize(stateManager, app);
        this.app = (MainApp) app;
        if (niftyDisplay == null) {
            niftyDisplay = new NiftyJmeDisplay(app.getAssetManager(),
                    app.getInputManager(),
                    app.getAudioRenderer(),
                    app.getGuiViewPort());
        }
        nifty = niftyDisplay.getNifty();
        nifty.fromXml("Interface/Nifty/menu.xml", "menu", this);
        app.getGuiViewPort().addProcessor(niftyDisplay);
    }

    @Override
    public void update(float tpf) {
        super.update(tpf);
    }

    @Override
    public void stateDetached(AppStateManager stateManager) {
        app.getGuiViewPort().removeProcessor(niftyDisplay);
    }

    public void startGame() {
        app.loadGame();
    }

    public void quitGame() {
        app.stop();
    }

    @Override
    public void bind(Nifty nifty, Screen screen) {
        this.nifty = nifty;
    }

    @Override
    public void onStartScreen() {
    }

    @Override
    public void onEndScreen() {
    }
}
